<script setup lang="ts">
import avatar from '@/assets/images/aside_author_image.jpg';
import { useWebConfigStore } from '@/stores';
import { selectStatistics } from '@/api/statistics';
import { ref } from 'vue';
const webConfigStore = useWebConfigStore();
const author  = ref({
  name: 'II',
  avatar: avatar,
  motto: 'Chasing Starlight',
  website: 'https://www.starmist.net',
  stats: {
    articles: 0,
    tags: 0,
    comments: 0
  }
});
const getStatistics = async () => {
  const result = await selectStatistics();
  author.value.stats.articles = result.data.articles;
  author.value.stats.tags = result.data.category;
  author.value.stats.comments = result.data.comment;
};
getStatistics();
// 图片加载错误处理
const handleImageError = (e: Event) => {
  console.error('图片加载失败');
};
</script>

<template>
    <div class="author-profile box-shadow box-radius">
      <div class="cover-image">
        <img
          class="bg-image"
          :src="webConfigStore.profileBackground"
          alt="Profile Background"
          loading="lazy"
        >
      </div>

      <div class="author-info">
        <img
          class="avatar"
          :src="webConfigStore.profileAvatar"
          :alt="author.name"
          loading="lazy"
          @error="handleImageError"
        >
        <a
          class="name"
          :href="author.website"
          target="_blank"
          rel="noopener noreferrer"
        >
          {{ author.name }}
        </a>
        <p class="motto" :title="author.motto">{{ author.motto }}</p>
      </div>

      <div class="stats">
        <div class="stat-item" title="累计文章数">
          <span class="number">{{ author.stats.articles }}</span>
          <span class="label">文章数</span>
        </div>
        <div class="stat-item" title="累计标签数">
          <span class="number">{{ author.stats.tags }}</span>
          <span class="label">标签数</span>
        </div>
        <div class="stat-item" title="累计评论数">
          <span class="number">{{ author.stats.comments }}</span>
          <span class="label">评论量</span>
        </div>
      </div>
    </div>
</template>

<style scoped lang="less">
.author-profile {
  position: relative;
  padding: 85px 15px 15px;
  background-color: #ffffff;
  transition: all 0.3s ease;
  margin-bottom: 24px;

  &:hover {

    .avatar {
      transform: rotate(360deg);
    }
  }

  .cover-image {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 120px;
    overflow: hidden;
    border-radius: 12px 12px 0 0;
    z-index: 1;

    .bg-image {
      width: 100%;
      height: 100%;
      object-fit: cover;
      transition: transform 0.3s ease;

      &:hover {
        transform: scale(1.05);
      }
    }
  }

  .author-info {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: 20px;

    .avatar {
      width: 70px;
      height: 70px;
      border-radius: 50%;
      border: 3px solid rgba(255, 255, 255, 0.5);
      object-fit: cover;
      transition: all 0.75s ease;
      margin-bottom: 12px;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .name {
      color: #73aaff;
      font-size: 16px;
      font-weight: 500;
      margin-bottom: 8px;
      transition: color 0.3s ease;

      &:hover {
        color: darken(#73aaff, 10%);
      }
    }

    .motto {
      color: #404044;
      text-align: center;
      font-size: 14px;
      line-height: 1.5;
      margin: 0;
      opacity: 0.9;
    }
  }

  .stats {
    display: flex;
    justify-content: space-around;
    padding: 15px 0;
    border-top: 1px dashed rgba(0, 0, 0, 0.1);
    z-index: 2;

    .stat-item {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 0 8px;

      .number {
        font-size: 18px;
        font-weight: 600;
        color: #404044;
        margin-bottom: 4px;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
      }

      .label {
        font-size: 13px;
        color: #606266;
        opacity: 0.8;
      }
    }
  }
}
</style>
